package com.py.pythink.service.impl;

import com.py.pythink.bo.SellerQueryBo;
import com.py.pythink.bo.SellersBo;
import com.py.pythink.config.RedisKeyConfig;
import com.py.pythink.config.SystemConfig;
import com.py.pythink.dao.SellersDao;
import com.py.pythink.service.intf.SellersService;
import com.py.pythink.third.JedisUtil;
import com.py.pythink.util.BeanUtil;
import com.py.pythink.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SellersServiceImpl  implements SellersService {
    @Autowired
    private SellersDao dao;



    /**
     * 通过小区进行查询*/
    public R queryByAddress(String address){
        if(address!=null){
            List<SellersBo> list = dao.selectByAddress(address);
            return R.ok(list);
        }
        return R.fail();
    }

    /**
     * 城市*/
    @Override
    public R queryByCity(String city) {
        if (!city.isEmpty()){
            List<SellersBo> list = dao.selectByCity(city);
            return R.ok(list);
        }
        return R.fail();
    }

    /**
     * 总价*/
    @Override
    public R queryByPrice(int min,int max) {
        if (min > 0 && max > 0) {
            if (min > max) {
                return R.fail("你输入的最低价格大于最高价格请重新输入");
            }
            List<SellersBo> list = dao.selectByPrice(min, max);
            if (list.isEmpty()) {
                return R.fail("暂无该价位的房屋");
            }
            return R.ok(list);
        }
        return R.fail("价格必须大于0");
    }

    /**
     * 单价*/

    @Override
    public R queryByUnivalence(int min, int max) {
        if (min > 0 && max > 0) {
            if (min > max) {
                return R.fail("你输入的最低价格大于最高价格请重新输入");
            }
            List<SellersBo> list = dao.selectByUnivalence(min, max);
            if (list.isEmpty()) {
                return R.fail("暂无该价位的房屋");
            }
            return R.ok(list);
        }
        return R.fail("价格必须大于0");
    }

    /**
     * 户型*/
    @Override
    public R queryByHousetype(int housetype) {
        if (housetype >= SystemConfig.HOUSETYPE_1 && housetype <= SystemConfig.HOUSETYPE_5) {
            List<SellersBo> list = dao.selectByHousetype(housetype);
            return R.ok(list);
        }
        return R.fail("没有该户型的房屋");
    }



    /**
     * 单价排序*/
    @Override
    public R sortByUnivalence(int type) {
            if (type== SystemConfig.UNIVALENCE_1){
                List<SellersBo>list = dao.selectByUnivalence1();
                return R.ok(list);
            }else if (type == SystemConfig.UNIVALENCE_2){
                List<SellersBo>list = dao.selectByUnivalence2();
                return R.ok(list);
            }else {
                return R.fail();
            }

    }
/**
 * 通过开盘时间排序*/
    @Override
    public R sortByFtime(int type) {

            if (type== SystemConfig.OPENTIME_1){
                List<SellersBo>list = dao.selectByOpentime1();
                return R.ok(list);
            }else if (type == SystemConfig.OPENTIME__2){
                List<SellersBo>list = dao.selectByOpentime2();
                return R.ok(list);
            }else {
                return R.fail();
            }

        }

    @Override
    public R queryByMore(SellerQueryBo bo) {
        if (bo.getDecoration()>=SystemConfig.DECORATION_1 && bo.getDecoration()<=SystemConfig.DECORATION_3) {
            List<SellersBo> list = dao.selectByMore(bo);
            try {
                if (bo.getMin() > 0 && bo.getMax() > 0) {
                    if (bo.getMin() > bo.getMax()) {
                        return R.fail("你输入的最小面积大于最大面积请重新输入");
                    }
                    List<SellersBo> list1 = dao.selectByMore(bo);

                    return R.ok(list1);
                }
            }catch (Exception e){
                e.printStackTrace();
            }

            return R.ok(list);
        }
        return R.fail("面积必须大于0");
    }

}
